package com.sfy.login.third;


import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.*;

/**
 * @Description
 * @Author 谷晓天
 * @Date 2021/7/2 9:30 下午
 */
public class JedisUtil {
    public static final String HOST = "39.105.76.161";
    public static final Integer PORT = 6379;
    public static final String PASSWORD = "Sfy@ywy0315";
    private static Jedis client;
    static {
        JedisPool pool=new JedisPool(HOST,PORT);
        client = pool.getResource();
        client.auth(PASSWORD);
    }
    //新增
    public static void addStr(String key,String val,long seconds){
        client.setex(key,seconds,val);
    }
    //查询
    public static String getStr(String key){
        return client.get(key);
    }
    //校验
    public static boolean checkKey(String key){
        return client.exists(key);
    }
    //返回剩余有效期
    public static long ttl(String key){
        return client.ttl(key);
    }
    //删除
    public static boolean delKey(String key){
        return client.del(key) > 0;
    }

    public static long incr(String key) {
        return client.incr(key);
    }

    public static long sadd(String key,String val) {
        return client.sadd(key,val);
    }

    public static Set<String> smembers(String key) {
        return client.smembers(key);
    }
    /**
     * 刷新 key 的有效期
     */
    public static void expire(String key,long seconds) {
        client.expire(key,seconds);
    }
}
